﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace FasterWPF
{
    public static class PopupExt
    {
        //public static Popup SetBackgroundColor(this Popup chain, Brush brush)
        //{
        //    Brush newBrush = (brush);
        //    chain.Background = newBrush;
        //    return chain;
        //}

        public static Popup Initialize(this Popup source, ContainerType containerType, bool isOpen, UIElement placementTarget, PopupAnimation animation, bool staysOpen)
        {
            return source.Initialize(double.NaN, double.NaN, containerType, isOpen, placementTarget, animation, staysOpen);
        }

        public static Popup Initialize(this Popup source, double width, double height, ContainerType containerType, bool isOpen, UIElement placementTarget, PopupAnimation animation, bool staysOpen)
        {   
            //Force the Aero theme by default to assure the structure of the Listbox
            Uri uri = new Uri("/PresentationFramework.Aero;component/themes/Aero.NormalColor.xaml", UriKind.Relative);
            source.Resources.MergedDictionaries.Add(Application.LoadComponent(uri) as ResourceDictionary);

            source.SetContainerType(containerType);
            IComposite icomp = CompositeTypeHelper.CreateIComposite<Popup>(source);
            source.SetIComposite<Popup>(icomp);

            source.IsOpen = isOpen;
            source.Width = width;
            source.Height = height;
            source.PlacementTarget = placementTarget;
            source.PopupAnimation = animation;
            source.StaysOpen = staysOpen;

            //STORE SETTING BUILD CHAIN AND GET CHAIN?!?  Put these in a Composite implements an interface
            PopupParent gbsr = new PopupParent();
            source.StoreSetting<Popup>("IParent", gbsr);

            source.AddItemBorder(Brushes.Gray, new Thickness(1, 1, 1, 1)); //default Border     
            source.StoreSetting<Popup>("BorderSettings", new BorderSettings() { Width = double.NaN, Height = double.NaN, BorderBrush = Brushes.Gray, BorderThickness = new Thickness(0, 0, 0, 0), CornerRadius = new CornerRadius(0), Padding = new Thickness(0) });

            return source;
        }
        
    }//end of class
}//end of namespace
